Page({
  data: {
    address: {},
    cart: [],
    totalPrice: 0,
    totalNum: 0
  },
  onShow() {
    // 1 获取缓存中的收货地址信息
    const address = wx.getStorageSync("address");
    // 1 获取缓存中的购物车数据
    let goodslist = wx.getStorageSync("goodslist") || [];
    // 过滤后的购物车数组
    goodslist = goodslist.filter(v => v.checked);
    this.setData({ address });

    // 1 总价格 总数量
    let totalPrice = 0;
    let totalNum = 0;
    goodslist.forEach(v => {
      totalPrice += v.count * v.goods_price;
      totalNum += v.count;
    })
    this.setData({
      goodslist,
      totalPrice, totalNum,
      address
    });
  }
})



